package com.zhaoxi.project.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.mes.domain.MesWorkshop;
import com.zhaoxi.project.mes.service.impl.MesWorkshopServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 生产车间Controller
 * 
 * @author zhaoxi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/mes/workshop")
public class MesWorkshopController extends BaseController
{
    @Autowired
    private MesWorkshopServiceImpl mesWorkshopService;

    /**
     * 查询生产车间列表
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesWorkshop mesWorkshop)
    {
        startPage();
        List<MesWorkshop> list = mesWorkshopService.selectMesWorkshopList(mesWorkshop);
        return getDataTable(list);
    }

    /**
     * 导出生产车间列表
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:export')")
    @Log(title = "生产车间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesWorkshop mesWorkshop)
    {
        List<MesWorkshop> list = mesWorkshopService.selectMesWorkshopList(mesWorkshop);
        ExcelUtil<MesWorkshop> util = new ExcelUtil<MesWorkshop>(MesWorkshop.class);
        util.exportExcel(response, list, "生产车间数据");
    }

    /**
     * 获取生产车间详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesWorkshopService.selectMesWorkshopById(id));
    }

    /**
     * 新增生产车间
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:add')")
    @Log(title = "生产车间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesWorkshop mesWorkshop)
    {
        return toAjax(mesWorkshopService.insertMesWorkshop(mesWorkshop));
    }

    /**
     * 修改生产车间
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:edit')")
    @Log(title = "生产车间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesWorkshop mesWorkshop)
    {
        return toAjax(mesWorkshopService.updateMesWorkshop(mesWorkshop));
    }

    /**
     * 删除生产车间
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:remove')")
    @Log(title = "生产车间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesWorkshopService.deleteMesWorkshopByIds(ids));
    }
}
